package com.ashin;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.ashin.bean.Page;
import com.ashin.bean.User;
import com.ashin.dao.UserDao;

/**
 * 改用例单纯使用mybatis，举例Mybaties的使用方式，没有和spring整合
 *
 * @author Ashin
 */
public class MybatisDemo {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        // 一个应用允许使用一个session即可
        SqlSession session = sqlSessionFactory.openSession();

        UserDao userDao = session.getMapper(UserDao.class);


        Map<String, Object> cond1 = new HashMap<>();
        cond1.put("id", 1);
        System.out.println(userDao.queryUserList(cond1));

        session.commit();
        session.close();
    }

}
